package org.jash.shop2201.entity

import androidx.databinding.BaseObservable
import androidx.databinding.Bindable
import org.jash.shop2201.BR
import org.jash.shop2201.utils.bus

data class CartItem(
    val goods_default_icon: String,
    val goods_default_price: Float,
    val goods_desc: String,
    val goods_id: Int,
    val id: Int,
    val order_id: Int,
    val user_id: Int
):BaseObservable() {
    @Bindable
    var checked = false
        set(value) {
            field = value
            bus.postValue("更新购物车" to "")
            notifyPropertyChanged(BR.checked)
        }
    @Bindable
    var count: Int = 0
        set(value) {
            if (value >= 1){
                field = value
                notifyPropertyChanged(BR.count)
                if (checked) {
                    bus.postValue("更新购物车" to "")
                }
            }

        }
    fun changedCount(i:Int) {
        count += i
    }
    fun deleteCart() {
        bus.postValue("删除购物车" to this)
    }
    val coupon
        get() = (goods_default_price * count) - count / 2 * goods_default_price * 0.5f
}